<?
$help['svn:merge'] = 'merge revisions to RC/REL';
$opt['svn:merge'] = array('revisions', 'bug');

function cmd_svn_merge($revisions, $bug){
    global $config;
    
    if(!file_exists('../.branch')){
        echo "You have to checkout RC/REL first\n";
        exit;
    }
    $branch = file_get_contents('../.branch');

    $cmp = file_get_contents('.component');
    
    echo "Merging component $cmp\n";
    
    $rvs = array();
    while($rev = array_shift($revisions))
        array_push($rvs, (preg_match('/:/', $rev) ? '-r' : '-c') . $rev);
    
    $stack = '';
    
    foreach($rvs as $r){
        echo ($cmd = "svn merge $r ${config['svnroot']}/${config['cprefix']}${cmp}/trunk") . "\n\n";
        passthru($cmd);
        $stack .=  "\n" . $cmd;
    }
    
    echo "\n\nsvn ci -m 'Bug $bug: merge to $branch" . $stack . "'\n";
    
}